package de.tum.in.eist.poll.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;

/**
 * This class contains a panel which is shown after log in.
 */
public class LoggedInView extends HorizontalPanel {
	private Button logout = new Button();
	private Label loginText = new Label();
	
	/**
	 * As soon as the user is logged in this panel replaces the Login-panel.
	 * This panel provides a Logout-Button and shows the user which user is logged in.
	 */
	public LoggedInView(){
		
		if(EIST_POLL.currentUser!=null)
		loginText.setText("Logged in as "+EIST_POLL.currentUser.getName()+".");
		
		logout.setText("Logout");
		logout.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				EIST_POLL.currentUser = null;
				Window.Location.reload();
			}
		});
		
		
		
		this.add(loginText);
		this.add(logout);
	}
}
